package com.huawei.hwid.core.c;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.text.TextUtils;
import com.huawei.hwid.core.encrypt.c;
import com.huawei.hwid.f.g;

public class a {
    private static a a;
    private SharedPreferences b;
    private Context c;

    public a(Context context) {
        this.b = context.getSharedPreferences("HwAccount", 0);
        this.c = context.getApplicationContext();
    }

    public static synchronized a a(Context context) {
        a aVar;
        synchronized (a.class) {
            if (a == null) {
                a = new a(context);
            }
            aVar = a;
        }
        return aVar;
    }

    public String a(String str, String str2) {
        if (this.b != null) {
            str2 = this.b.getString(str, str2);
        }
        if (str.equals("rkey")) {
            return str2;
        }
        CharSequence c = c.c(this.c, str2);
        if (TextUtils.isEmpty(c)) {
            return str2;
        }
        return c;
    }

    public int a(String str, int i) {
        return this.b != null ? this.b.getInt(str, i) : i;
    }

    public void b(String str, String str2) {
        Editor edit = this.b.edit();
        if (edit != null) {
            edit.putString(str, c.b(this.c, str2)).commit();
        }
    }

    public boolean a(String str, Object obj) {
        Editor edit = this.b.edit();
        if (obj instanceof String) {
            edit.putString(str, String.valueOf(obj));
        } else if ((obj instanceof Integer) || (obj instanceof Short) || (obj instanceof Byte)) {
            edit.putInt(str, g.a(String.valueOf(obj)));
        } else if (obj instanceof Long) {
            edit.putLong(str, ((Long) obj).longValue());
        } else if (obj instanceof Float) {
            edit.putFloat(str, ((Float) obj).floatValue());
        } else if (obj instanceof Double) {
            edit.putFloat(str, (float) ((Double) obj).doubleValue());
        } else if (obj instanceof Boolean) {
            edit.putBoolean(str, ((Boolean) obj).booleanValue());
        }
        return edit.commit();
    }

    public void a(String str) {
        Editor edit = this.b.edit();
        if (edit != null) {
            edit.remove(str).commit();
        }
    }
}
